<template>
	<view class="order">
		<view class="status">
			订单{{State==0?'已发货':State==1?'已收货':'已还款'}}
		</view>
		<view class="container">
			<view class="cell">
				账期：{{entity.AccountingStartTime?entity.AccountingStartTime.substring(0,11):''}} ~ {{entity.AccountingEndTime?entity.AccountingEndTime.substring(0,11):''}}
			</view>
			<view class="cell">
				赊账金额：￥{{momenyFormat(entity.TotalSum) || 0}}
			</view>
		</view>
		<view class="container">
			<view class="cell"><text>单号：</text>{{ entity.SalesOrder }}</view>
			<view class="cell">
				<text>日期：</text>{{ entity.CreateTime?entity.CreateTime.substring(0, 10):'' }}
			</view>
			<view class="cell"><text>卖家：</text>{{ entity.CompanyName ||'' }}</view>
			<view class="cell"><text>地址：</text>{{ entity.CompauyAddress||'' }}</view>
			<view class="cell"><text>电话：</text>{{ entity.CompauyPhone||'' }}</view>
		</view>
		<view class="container">
			<view class="tableRow" style="border-bottom: 1px dashed #ccc; margin-top: 10px; line-height: 2">
				<text class="tableIndex"></text>
				<text class="tableCol left">品名/编码</text>
				<text class="tableCol">数量</text>
				<text class="tableCol">单价</text>
				<text class="tableCol">金额</text>
			</view>
			<view style="padding: 10px 0">
				<view v-for="(item, index) in data" :key="index">
					<view class="tableRow">
						<text class="tableIndex">{{ index + 1 }}</text>
						<text class="tableCol left">{{ item.InventName || ""}}</text>
						<text class="tableCol">{{ item.Quantity||1 }}</text>
						<!-- <text class="tableCol">{{ item.GroupName }}</text> -->
						<text class="tableCol">{{ momenyFormat(item.Price) || 0}}</text>
						<text class="tableCol">{{ momenyFormat(item.Money)  || 0}}</text>
					</view>
					<view class="tableRow">
						<text class="tableIndex"></text>
						<text class="tableCol left">{{ item.cInvCode||'' }}</text>
						<text class="tableCol">{{ item.GroupName||'' }}</text>
						<text v-if="item.cInvStd" class="tableCol col2">规格: {{ item.cInvStd }}</text>
						<!-- <text class="tableCol">{{ item.GroupName }}</text> -->
					</view>
				</view>
			</view>

			<view class="tableRow" style="border-top: 1px dashed #ccc; line-height: 2; margin-bottom: 10px">
				<text class="tableIndex"></text>
				<text class="tableCol left">合计</text>
				<text class="tableCol">{{ entity.TotalQuantity }}</text>
				<text class="tableCol"></text>
				<text class="tableCol" style="">{{ momenyFormat(entity.TotalSum) }}</text>
			</view>
		</view>

	</view>
</template>

<script>
	import {
		momenyFormat
	} from '@/utils/utils.js'
	export default {
		data() {
			return {
				entity: {},
				data: [],
				momenyFormat,
				State:0
			}
		},
		// onBackPress() {
		// 	console.log('监听返回')
		// 	uni.reLaunch({
		// 		url:'/pages/Order/Order'
		// 	})
		// 	return true
		// },
		onLoad(options) {
			
			this.State=options.State
			// 获取订单详情数据
			this.GetApplicationDetail(options.Id)
		},
		methods: {
			// 获取订单详情数据
			GetApplicationDetail(orderId){
				this.$http('post', '/BO/BIlling/GetBllingDetail?id='+orderId).then(res => {
					if (res.Success) {
						this.entity=res.Data.maindata
						this.data = res.Data.detalist
						let TotalQuantity=0
						let TotalSum=0
						this.data.forEach(item=>{
							TotalQuantity+=item.Quantity
							TotalSum+=item.Price*item.Quantity
							// this.entity.TotalQuantity+=item.Quantity
						})
						this.entity.TotalQuantity = TotalQuantity
						this.entity.TotalSum = TotalSum
						
					} else this.$api.msg(res.Msg)
				})
			}

		}
	}
</script>

<style scoped lang="scss">
	.status {
		padding-left: 30rpx;
		font-size: 18px;
		font-weight: 600;
	}

	.container {
		background-color: #fff;
		margin: 10px 30rpx;
		color: #000;
		padding: 10px;
		border-radius: 5px;

		.cell {
			display: flex;
			line-height: 2;

			span {
				width: 40px;
			}
		}

		.tableRow {
			font-size: 12px;
			display: flex;
			align-items: center;

			span {
				overflow: hidden;
			}

			.tableCol {
				// flex: 1;
				width: 75px;
				text-align: right;
				overflow: hidden;
			}

			.tableInp {
				font-size: 12px;
				width: 75px;
				text-align: right;
				overflow: hidden;
				border: 1px solid #ccc;
				padding: 4px;
				border-radius: 4px;
			}

			.left {
				text-align: left;
				flex: 1;
			}

			.tableIndex {
				width: 25px;
			}

			.col2 {
				width: 150px;
			}
		}
	}
</style>